import { Map } from "immutable";

import * as actionTypes from "./constants";

const defaultValue = Map({
  //正在播放的歌曲
  currentSong: {},
  //播放列表
  playList: [],
  //当前播放的索引
  currentSongIndex: 0,
  //播放类型  0 循环 1 随机 2 单曲
  sequence: 0,
  //歌词
  lyricList: [],
  //歌词索引
  lyRiCIndex: 0,
});

function ruducer(state = defaultValue, action) {
  switch (action.type) {
    case actionTypes.CHANGE_CURRENT_SONG:
      return state.set("currentSong", action.currentSong);
    case actionTypes.CHANGE_CURRENT_INDEX:
      return state.set("currentSongIndex", action.index);
    case actionTypes.CHANGE_PLAYLIST_ACTION:
      return state.set("playList", action.playList);
    case actionTypes.CHANGE_SEQUENCE_ACTION:
      return state.set("sequence", action.sequence);
    case actionTypes.CHANG_LYRIC_ACTION:
      return state.set("lyricList", action.lyricList);
    case actionTypes.CHANGE_LYRIC_INDEX:
      return state.set("lyRiCIndex", action.index);
    default:
      return state;
  }
}

export default ruducer;
